package com.gpframework.module.controller.module;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.common.utils.poi.ExcelUtil;
import com.gpframework.module.module.domain.GpIncomingInspect;
import com.gpframework.module.module.domain.req.GpIncomingInspectReq;
import com.gpframework.module.module.domain.req.GpIncomingInspectUpdate;
import com.gpframework.module.module.domain.vo.GpIncomingInspectVo;
import com.gpframework.module.module.service.IGpIncomingInspectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
/**
 * @ClassName GpIncomingInspectController
 * @Author gpframework
 * @Date 2023-12-11
 * @Version 1.0.0
 * @Description 来料检验单Controller
 */
@Validated
@Api(tags = "来料检验单")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/module/incominginspect" )
public class GpIncomingInspectController extends BaseController {

    private final IGpIncomingInspectService iGpIncomingInspectService;







    /**
  * @Description 分页
  * @Author gpframework
  * @Date 2023-12-11
  * @Param gpIncomingInspect
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('module:incominginspect:list')")
    @GetMapping("/list")
    public TableDataInfo<GpIncomingInspectVo> list(GpIncomingInspectReq gpIncomingInspectReq)
    {
        startPage();
        QueryWrapper<GpIncomingInspect> lqw = new QueryWrapper<GpIncomingInspect>();
        gpIncomingInspectReq.generatorQuery(lqw,true);
        List<GpIncomingInspectVo> list = iGpIncomingInspectService.listVo(lqw);

        return getDataTable(list);
    }


    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('module:incominginspect:edit')" )
    @Log(title = "修改来料检验单" , businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@Valid @RequestBody List<GpIncomingInspectUpdate> gpIncomingInspectUpdateList) {
//        GpIncomingInspect gpIncomingInspect = Convert.convert(new TypeReference<GpIncomingInspect>() {}, gpIncomingInspectUpdate);
        return toAjax(iGpIncomingInspectService.updateByWeightAndWidthAndYardVerify(gpIncomingInspectUpdateList) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */

    @ApiOperation("导出来料检验单")
    @PreAuthorize("@ss.hasPermi('module:incominginspect:export')" )
    @Log(title = "导出来料检验单" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(GpIncomingInspectReq gpIncomingInspectReq) {
        QueryWrapper<GpIncomingInspect> lqw = new QueryWrapper<GpIncomingInspect>();
        gpIncomingInspectReq.generatorQuery(lqw,true);
        List<GpIncomingInspectVo> list = iGpIncomingInspectService.listVo(lqw);
        ExcelUtil<GpIncomingInspectVo> util = new ExcelUtil<GpIncomingInspectVo>(GpIncomingInspectVo. class);
        return util.exportExcel(list, "incominginspect" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('module:incominginspect:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpIncomingInspectVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpIncomingInspectService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('module:incominginspect:remove')" )
    @Log(title = "删除来料检验单" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpIncomingInspectService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }


    /**
     * @Description 生成克重表
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */

    @ApiOperation("生成克重表")
    @PreAuthorize("@ss.hasPermi('module:deliverynote:addWeightMeter')" )
    @Log(title = "生成克重表" , businessType = BusinessType.INSERT)
    @PostMapping("/addWeightMeter")
    public AjaxResult addWeightMeter(@RequestBody GpIncomingInspectUpdate gpIncomingInspectUpdate) {
        if (gpIncomingInspectUpdate == null || CollectionUtils.isEmpty(gpIncomingInspectUpdate.getIds())) {
            return AjaxResult.parameterError();
        }


        return toAjax(iGpIncomingInspectService.addWeightMeter(gpIncomingInspectUpdate) ? 1 : 0);
    }

    /**
     * @Description 生成色牢度表
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */

    @ApiOperation("生成色牢度表")
    @PreAuthorize("@ss.hasPermi('module:deliverynote:addColorFastness')" )
    @Log(title = "生成色牢度表" , businessType = BusinessType.INSERT)
    @PostMapping("/addColorFastness")
    public AjaxResult addColorFastness(@Valid @RequestBody GpIncomingInspectUpdate gpIncomingInspectUpdate) {
        if (gpIncomingInspectUpdate == null || CollectionUtils.isEmpty(gpIncomingInspectUpdate.getIds())) {
            return AjaxResult.parameterError();
        }
        return toAjax(iGpIncomingInspectService.addColorFastness(gpIncomingInspectUpdate) ? 1 : 0);
    }



    /**
     * @Description 生成甲醛表
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */

    @ApiOperation("生成甲醛表")
    @PreAuthorize("@ss.hasPermi('module:deliverynote:addFormalde')" )
    @Log(title = "生成甲醛表" , businessType = BusinessType.INSERT)
    @PostMapping("/addFormalde")
    public AjaxResult addFormalde(@Valid @RequestBody GpIncomingInspectUpdate gpIncomingInspectUpdate) {
        if (gpIncomingInspectUpdate == null || CollectionUtils.isEmpty(gpIncomingInspectUpdate.getIds())) {
            return AjaxResult.parameterError();
        }
        return toAjax(iGpIncomingInspectService.addFormalde(gpIncomingInspectUpdate) ? 1 : 0);
    }

    /**
     * @Description 生成品质反馈表
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */

    @ApiOperation("生成品质反馈表")
    @PreAuthorize("@ss.hasPermi('module:deliverynote:addQualityfeedback')" )
    @Log(title = "生成品质反馈表" , businessType = BusinessType.INSERT)
    @PostMapping("/addQualityfeedback")
    public AjaxResult addQualityfeedback(@Valid @RequestBody GpIncomingInspectUpdate gpIncomingInspectUpdate) {
        if (gpIncomingInspectUpdate == null || CollectionUtils.isEmpty(gpIncomingInspectUpdate.getIds())) {
            return AjaxResult.parameterError();
        }
        return toAjax(iGpIncomingInspectService.addQualityfeedback(gpIncomingInspectUpdate) ? 1 : 0);
    }

    /**
     * @Description 品质问题跟踪明细
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */

    @ApiOperation("品质问题跟踪明细")
    @PreAuthorize("@ss.hasPermi('module:deliverynote:qualityIssueTrackDetails')" )
    @Log(title = "品质问题跟踪明细" , businessType = BusinessType.INSERT)
    @PostMapping("/qualityIssueTrackDetails")
    public AjaxResult qualityIssueTrackDetails(@Valid @RequestBody GpIncomingInspectUpdate gpIncomingInspectUpdate) {
        if (gpIncomingInspectUpdate == null || CollectionUtils.isEmpty(gpIncomingInspectUpdate.getIds())) {
            return AjaxResult.parameterError();
        }
        return toAjax(iGpIncomingInspectService.qualityIssueTrackDetails(gpIncomingInspectUpdate) ? 1 : 0);
    }


    /**
     * @Description 复制
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpIncomingInspect
     * @Return TableDataInfo
     */
    @ApiOperation("复制")
    @PreAuthorize("@ss.hasPermi('module:deliverynote:add')" )
    @Log(title = "复制" , businessType = BusinessType.INSERT)
    @PostMapping("/copy")
    public AjaxResult copy(@RequestBody GpIncomingInspectUpdate gpIncomingInspectUpdate) {
        if (gpIncomingInspectUpdate == null || gpIncomingInspectUpdate.getId() == null || gpIncomingInspectUpdate.getCopyNum() == null) {
            return AjaxResult.parameterError();
        }
        if (gpIncomingInspectUpdate.getCopyNum() < 1) {
            return AjaxResult.error("复制条数不能小于1");
        }
        return toAjax(iGpIncomingInspectService.copy(gpIncomingInspectUpdate.getId(), gpIncomingInspectUpdate.getCopyNum()) ? 1 : 0);
    }
}
